package com.bj.zspace.bytebuddy.bbtest;

import com.bj.zspace.bytebuddy.normal_test.Service;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.NamingStrategy;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * 加载生成的类
 **/
public class GenerateLoadClass {
    public static final Logger log = LoggerFactory.getLogger(GenerateLoadClass.class);

    public static void main(String[] args) throws Exception {

        String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();

        Class<? extends Service> service = new ByteBuddy()
                .with(new NamingStrategy.SuffixingRandom("ByteBuddyClass"))
                .subclass(Service.class).make()
                .load(GenerateLoadClass.class.getClass()
                .getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                .getLoaded();
        Service instance = service.getDeclaredConstructor(new Class[0]).newInstance();
        instance.deleteEverything();
    }

}
